#include "widget.h"
#include "ui_widget.h"
//QSpinBox微调框-示例
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    create();
    //初始化下拉框
    box1->addItem("汉堡1");
    box1->addItem("汉堡2");
    box1->addItem("汉堡3");

    box2->addItem("薯条1");
    box2->addItem("薯条2");
    box2->addItem("薯条3");

    box3->addItem("饮料1");
    box3->addItem("饮料2");
    box3->addItem("饮料3");

    //对微调框进行设置
    //设置最小值和最大值
    spinbox1->setRange(0,5);
    spinbox2->setRange(0,5);
    spinbox3->setRange(0,5);
    //设置初始值
    spinbox1->setValue(0);
    spinbox2->setValue(0);
    spinbox3->setValue(0);

    connect(button,&QPushButton::clicked,this,&Widget::handler);

}

Widget::~Widget()
{
    delete ui;
}

void Widget::create()
{
    label1=new QLabel(this);
    label1->setGeometry(50,50,50,50);
    label1->setText("汉堡");
    label2=new QLabel(this);
    label2->setGeometry(50,100,50,50);
    label2->setText("薯条");
    label3=new QLabel(this);
    label3->setGeometry(50,150,50,50);
    label3->setText("饮料");

    box1=new QComboBox(this);
    box1->setGeometry(100,60,100,30);
    box2=new QComboBox(this);
    box2->setGeometry(100,110,100,30);
    box3=new QComboBox(this);
    box3->setGeometry(100,160,100,30);

    spinbox1=new QSpinBox(this);
    spinbox1->setGeometry(220,60,50,30);
    spinbox2=new QSpinBox(this);
    spinbox2->setGeometry(220,110,50,30);
    spinbox3=new QSpinBox(this);
    spinbox3->setGeometry(220,160,50,30);

    button=new QPushButton(this);
    button->setText("提交");
    button->setGeometry(50,200,220,50);
}

void Widget::handler()
{
    qDebug()<<label1->text()<<":"<<box1->currentText()<<" "<<spinbox1->value();
    qDebug()<<label2->text()<<":"<<box2->currentText()<<" "<<spinbox2->value();
    qDebug()<<label3->text()<<":"<<box3->currentText()<<" "<<spinbox3->value();
}

